namespace Sunny.UI;

public class Adler32
{
	private static uint checksum = 1u;

	public static uint ComputeHash(byte[] bytesArray, int byteStart, int bytesToRead)
	{
		uint num = checksum & 0xFFFFu;
		uint num2 = checksum >> 16;
		while (bytesToRead > 0)
		{
			int num3 = ((3800 > bytesToRead) ? bytesToRead : 3800);
			bytesToRead -= num3;
			while (--num3 >= 0)
			{
				num += (uint)(bytesArray[byteStart++] & 0xFF);
				num2 += num;
			}
			num %= 65521;
			num2 %= 65521;
		}
		checksum = (num2 << 16) | num;
		return checksum;
	}

	internal static byte[] BigEndian(uint value)
	{
		byte[] array = new byte[4];
		array[3] = (byte)value;
		array[2] = (byte)(value >> 8);
		array[1] = (byte)(value >> 16);
		array[0] = (byte)(value >> 24);
		return array;
	}

	internal static byte[] LittleEndian(uint value)
	{
		return new byte[4]
		{
			(byte)value,
			(byte)(value >> 8),
			(byte)(value >> 16),
			(byte)(value >> 24)
		};
	}
}
